Spot-On
spot-on-gui-server.h
1 /*
2 ** Copyright (c) 2011 - 10^10^10, Alexis Megas.
3 ** All rights reserved.
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
7 ** are met:
8 ** 1. Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** 3. The name of the author may not be used to endorse or promote products
14 ** derived from Spot-On without specific prior written permission.
15 **
16 ** SPOT-ON IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 ** SPOT-ON, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef _spoton_gui_server_h_
29 #define _spoton_gui_server_h_
30 
31 #include <QFileSystemWatcher>
32 #include <QQueue>
33 #include <QPointer>
34 #include <QSslSocket>
35 #include <QTcpServer>
36 #include <QTimer>
37 
38 #include "Common/spot-on-common.h"
39 
40 class spoton_gui_server_tcp_server: public QTcpServer
41 {
42  Q_OBJECT
43 
44  public:
45  spoton_gui_server_tcp_server(QObject *parent):QTcpServer(parent)
46  {
47  }
48 
50  {
51  while(!m_queue.isEmpty())
52  {
53  QPointer<QSslSocket> socket = m_queue.dequeue();
54 
55  if(socket)
56  socket->deleteLater();
57  }
58  }
59 
60  QSslSocket *nextPendingConnection(void)
61  {
62  if(m_queue.isEmpty())
63  return 0;
64  else
65  return m_queue.dequeue();
66  }
67 
68 #if QT_VERSION >= 0x050000
69  void incomingConnection(qintptr socketDescriptor);
70 #else
71  void incomingConnection(int socketDescriptor);
72 #endif
73 
74  private:
75  QQueue<QPointer<QSslSocket> > m_queue;
76 
77  signals:
78  void modeChanged(QSslSocket::SslMode mode);
79  void newConnection(void);
80 };
81 
83 {
84  Q_OBJECT
85 
86  public:
87  spoton_gui_server(QObject *parent);
89 
90  private:
91  QFileSystemWatcher m_fileSystemWatcher;
92 #if QT_VERSION >= 0x050000
93  QHash<qintptr, QByteArray> m_guiSocketData;
94  QHash<qintptr, bool> m_guiIsAuthenticated;
95 #else
96  QHash<int, QByteArray> m_guiSocketData;
97  QHash<int, bool> m_guiIsAuthenticated;
98 #endif
99  QTimer m_generalTimer;
100  void sendMessageToUIs(const QByteArray &message);
101 
102  private slots:
103  void slotAuthenticationRequested(const QString &peerInformation);
104  void slotClientConnected(void);
105  void slotClientDisconnected(void);
106  void slotEncrypted(void);
107  void slotFileChanged(const QString &path);
108  void slotForwardSecrecyRequest(const QByteArrayList &list);
109  void slotForwardSecrecyResponse(const QByteArrayList &list);
110  void slotModeChanged(QSslSocket::SslMode mode);
111  void slotNewEMailArrived(void);
112  void slotNotification(const QString &text);
113  void slotReadyRead(void);
114  void slotReceivedBuzzMessage(const QByteArrayList &list,
115  const QByteArrayList &keys);
116  void slotReceivedChatMessage(const QByteArray &message);
117  void slotSMPMessage(const QByteArrayList &list);
118  void slotStatusMessageReceived(const QByteArray &publicKeyHash,
119  const QString &status);
120  void slotTimeout(void);
121 
122  signals:
123  void buzzMagnetReceivedFromUI(const qint64 oid,
124  const QByteArray &magnet);
125  void buzzReceivedFromUI(const QByteArray &channel,
126  const QByteArray &channelType,
127  const QByteArray &name,
128  const QByteArray &id,
129  const QByteArray &message,
130  const QByteArray &sendMethod,
131  const QString &messageType,
132  const QByteArray &hashKey,
133  const QByteArray &hashType,
134  const QByteArray &dateTime);
135  void callParticipant(const QByteArray &keyType,
136  const qint64 oid);
137  void callParticipantUsingForwardSecrecy(const QByteArray &keyType,
138  const qint64 oid);
139  void callParticipantUsingGemini(const QByteArray &keyType,
140  const qint64 oid);
141  void detachNeighbors(const qint64 oid);
142  void disconnectNeighbors(const qint64 oid);
143  void echoKeyShare(const QByteArrayList &list);
144  void forwardSecrecyInformationReceivedFromUI(const QByteArrayList &list);
145  void forwardSecrecyResponseReceivedFromUI(const QByteArrayList &list);
146  void messageReceivedFromUI(const qint64 oid,
147  const QByteArray &name,
148  const QByteArray &message,
149  const QByteArray &sequenceNumber,
150  const QByteArray &utcDate,
151  const QString &keyType);
152  void populateStarBeamKeys(void);
153  void publicKeyReceivedFromUI(const qint64 oid,
154  const QByteArray &keyType,
155  const QByteArray &name,
156  const QByteArray &publicKey,
157  const QByteArray &signature,
158  const QByteArray &sPublicKey,
159  const QByteArray &sSignature,
160  const QString &messageType);
161  void publicizeAllListenersPlaintext(void);
162  void publicizeListenerPlaintext(const qint64 oid);
163  void purgeEphemeralKeyPair(const QByteArray &publicKeyHash);
164  void purgeEphemeralKeys(void);
165  void retrieveMail(void);
166  void shareLink(const QByteArray &link);
167  void smpMessageReceivedFromUI(const QByteArrayList &list);
168 };
169 
170 #endif
Definition: spot-on-gui-server.h:40
Definition: spot-on-gui-server.h:82